/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewJFrame.java
 *
 * Created on 2011-05-05, 23:37:06
 */
package Interface;

import org.db2.project.airline.dao.DAOException;
import org.db2.project.airline.dto.BookingDetails;
import org.db2.project.airline.model.FlightClassType;
import org.db2.project.airline.model.FlightPlan;
import org.db2.project.airline.service.BookingService;
import org.db2.project.airline.service.FlightClassPriceService;

import javax.swing.*;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;

/**
 * @author Martyna
 */
public class ZarezerwujBilet extends javax.swing.JFrame {

    private boolean isOneWay;

    private FlightPlan departureFlightPlan;

    private FlightPlan arrivalFlightPlan;

    private FlightClassType flightClassType;

    private BookingService bookingService = new BookingService();

    private FlightClassPriceService flightClassPriceService = new FlightClassPriceService();
    
    private WynikWyszukiwania wynikWyszukiwania;

    public ZarezerwujBilet(FlightPlan departureFlightPlan, FlightClassType flightClassType, WynikWyszukiwania wynikWyszukiwania) {

        
        this(departureFlightPlan, null, flightClassType, true, wynikWyszukiwania);
    }

    public ZarezerwujBilet(FlightPlan departureFlightPlan, FlightPlan arrivalFlightPlan,
                           FlightClassType flightClassType, boolean isOneWay, WynikWyszukiwania wynikWyszukiwania) {

        initComponents();

        SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm");

        this.wynikWyszukiwania = wynikWyszukiwania;
        this.departureFlightPlan = departureFlightPlan;
        this.arrivalFlightPlan = arrivalFlightPlan;
        this.flightClassType = flightClassType;
        this.isOneWay = isOneWay;

        ZLabel.setText(departureFlightPlan.getFlightRoute().getDepartureAirport().getName());
        DoLabel.setText(departureFlightPlan.getFlightRoute().getDestinationAirport().getName());
        DataPrzylotuLabel.setText(dateFormat.format(departureFlightPlan.getDepartureTime()));
        DataWylotuLabel.setText(dateFormat.format(departureFlightPlan.getArrivalTime()));
        NrLotuLabel.setText(departureFlightPlan.getCode());

        setReturnFlightLabels(!isOneWay);
        if (!isOneWay && arrivalFlightPlan != null) {
            jLabel18.setText(arrivalFlightPlan.getFlightRoute().getDepartureAirport().getName());
            jLabel19.setText(arrivalFlightPlan.getFlightRoute().getDestinationAirport().getName());
            jLabel20.setText(arrivalFlightPlan.getCode());
            jLabel21.setText(dateFormat.format(arrivalFlightPlan.getDepartureTime()));
            jLabel22.setText(dateFormat.format(arrivalFlightPlan.getArrivalTime()));
        }
    }

    private void setReturnFlightLabels(boolean visible) {

        jLabel13.setVisible(visible);
        jLabel14.setVisible(visible);
        jLabel15.setVisible(visible);
        jLabel16.setVisible(visible);
        jLabel17.setVisible(visible);

        jLabel18.setVisible(visible);
        jLabel19.setVisible(visible);
        jLabel20.setVisible(visible);
        jLabel21.setVisible(visible);
        jLabel22.setVisible(visible);
    }

    /**
     * Creates new form NewJFrame
     */
    @Deprecated
    public ZarezerwujBilet(String Z, String Do, String DataWylotu, String DataPrzylotu, String NrLotu,WynikWyszukiwania wynikWyszukiwania) {
        initComponents();
        this.wynikWyszukiwania = wynikWyszukiwania;
        ZLabel.setText(Z);
        DoLabel.setText(Do);
        DataPrzylotuLabel.setText(DataPrzylotu);
        DataWylotuLabel.setText(DataWylotu);
        NrLotuLabel.setText(NrLotu);

        isOneWay = false;
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
     * content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        ImieTextField = new javax.swing.JTextField();
        NazwiskoTextFiled = new javax.swing.JTextField();
        NarodowoscTextField = new javax.swing.JTextField();
        AdresTextField = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        ZLabel = new javax.swing.JLabel();
        DoLabel = new javax.swing.JLabel();
        NrLotuLabel = new javax.swing.JLabel();
        DataWylotuLabel = new javax.swing.JLabel();
        DataPrzylotuLabel = new javax.swing.JLabel();
        TelefonTextField = new javax.swing.JFormattedTextField();
        EmailTextField = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Zarezerwuj Bilet"));

        jLabel1.setText("Nr Lotu:");

        jLabel2.setText("Imię");

        jLabel3.setText("Nazwisko");

        jLabel4.setText("Narodowość");

        jLabel5.setText("Adres");

        jLabel6.setText("Telefon");

        jLabel7.setText("E-mail");

        jLabel9.setText("Ilość");

        ImieTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ImieTextFieldActionPerformed(evt);
            }
        });

        NazwiskoTextFiled.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NazwiskoTextFiledActionPerformed(evt);
            }
        });

        NarodowoscTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NarodowoscTextFieldActionPerformed(evt);
            }
        });

        AdresTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AdresTextFieldActionPerformed(evt);
            }
        });

        jButton1.setText("Rezerwuj");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel8.setText("Z:");

        jLabel10.setText("Do:");

        jLabel11.setText("Data Wylotu:");

        jLabel12.setText("Data Przylotu:");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"1", "2", "3", "4", "5", "6", "7", "8"}));

        try {
            TelefonTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###-###-###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel13.setText("Data Przylotu:");

        jLabel14.setText("Data Wylotu:");

        jLabel15.setText("Nr Lotu:");

        jLabel16.setText("Do:");

        jLabel17.setText("Z:");

        jButton2.setText("Wstecz");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addContainerGap()
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                                                        .addComponent(ZLabel)
                                                        .addComponent(DoLabel)
                                                        .addComponent(NrLotuLabel)
                                                        .addComponent(DataWylotuLabel)
                                                        .addComponent(DataPrzylotuLabel))
                                                .addGap(139, 139, 139)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel14, javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel15, javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel16, javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel17, javax.swing.GroupLayout.Alignment.TRAILING))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jLabel22)
                                                        .addComponent(jLabel21)
                                                        .addComponent(jLabel20)
                                                        .addComponent(jLabel19)
                                                        .addComponent(jLabel18)))
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addContainerGap()
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(ImieTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 402, Short.MAX_VALUE)
                                                        .addComponent(NazwiskoTextFiled, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 402, Short.MAX_VALUE)
                                                        .addComponent(NarodowoscTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 402, Short.MAX_VALUE)
                                                        .addComponent(AdresTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 402, Short.MAX_VALUE)
                                                        .addComponent(TelefonTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 402, Short.MAX_VALUE)
                                                        .addComponent(EmailTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 402, Short.MAX_VALUE))))
                                .addContainerGap())
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(28, 28, 28)
                                .addComponent(jButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 275, Short.MAX_VALUE)
                                .addComponent(jButton2)
                                .addGap(38, 38, 38))
        );
        jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel8)
                                                        .addComponent(ZLabel))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel10)
                                                        .addComponent(DoLabel))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel1)
                                                        .addComponent(NrLotuLabel))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel11)
                                                        .addComponent(DataWylotuLabel))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel12)
                                                        .addComponent(DataPrzylotuLabel)))
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel17)
                                                        .addComponent(jLabel18))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel16)
                                                        .addComponent(jLabel19))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel15)
                                                        .addComponent(jLabel20))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel14)
                                                        .addComponent(jLabel21))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel13)
                                                        .addComponent(jLabel22))))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(ImieTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel3)
                                        .addComponent(NazwiskoTextFiled, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel4)
                                        .addComponent(NarodowoscTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel5)
                                        .addComponent(AdresTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel6)
                                        .addComponent(TelefonTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel7)
                                        .addComponent(EmailTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel9)
                                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jButton1)
                                        .addComponent(jButton2))
                                .addContainerGap(20, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addContainerGap())
        );
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        String imie, nazwisko, telefon, adres, email, narodowosc;
        int iloscBiletow;

        if (!validateForm()) {
            JOptionPane.showMessageDialog(this, "Prosze wypełnić wszystkie pola w formularzu.", "Nie wszysktkie pola są wypełnione",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        imie = ImieTextField.getText();
        nazwisko = NazwiskoTextFiled.getText();
        telefon = TelefonTextField.getText();
        adres = AdresTextField.getText();
        email = EmailTextField.getText();
        narodowosc = NarodowoscTextField.getText();
        iloscBiletow = Integer.parseInt(jComboBox1.getSelectedItem().toString());

        BookingDetails bookingDetails = new BookingDetails();
        bookingDetails.setClientFirstName(imie);
        bookingDetails.setClientLastName(nazwisko);
        bookingDetails.setClientPhoneNumber(telefon);
        bookingDetails.setClientAddress(adres);
        bookingDetails.setClientNationality(narodowosc);
        bookingDetails.setClientEmail(email);
        bookingDetails.setAmount(iloscBiletow);

        try {
            long[] ids;
            long departureBookingId = 0;
            long arrivalBookingId = 0;

            if (!isOneWay) {
                ids = bookingService.bookSeatsTwoWay(departureFlightPlan, arrivalFlightPlan, bookingDetails, flightClassType);

                departureBookingId = ids[0];
            } else {
                departureBookingId = bookingService.bookSeatsOneWay(departureFlightPlan, bookingDetails, flightClassType);
            }

            BigDecimal departureFlightPrice = flightClassPriceService.getFlightPrice(departureFlightPlan, flightClassType);
            departureFlightPrice = departureFlightPrice.multiply(new BigDecimal(iloscBiletow));

            new UdanaRezerwacja(departureBookingId, departureFlightPrice).setVisible(true);
            setVisible(false);
        } catch (DAOException e) {
            // TODO handle exception
            throw new RuntimeException(e);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private boolean validateForm() {

        List<JTextField> textFields = Arrays.asList(
                ImieTextField,
                NazwiskoTextFiled,
                TelefonTextField,
                AdresTextField,
                EmailTextField,
                NarodowoscTextField
        );

        for (JTextField textField : textFields) {

            if (textField.getText() == null || textField.getText().isEmpty()) {
                return false;
            }
        }

        return true;
    }

    private void AdresTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AdresTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_AdresTextFieldActionPerformed

    private void NarodowoscTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NarodowoscTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_NarodowoscTextFieldActionPerformed

    private void NazwiskoTextFiledActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NazwiskoTextFiledActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_NazwiskoTextFiledActionPerformed

    private void ImieTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ImieTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ImieTextFieldActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        
        wynikWyszukiwania.setVisible(true);
        this.setVisible(false);// TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                //new ZarezerwujBilet("Z", "Do", "d", "d", "d").setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField AdresTextField;
    private javax.swing.JLabel DataPrzylotuLabel;
    private javax.swing.JLabel DataWylotuLabel;
    private javax.swing.JLabel DoLabel;
    private javax.swing.JTextField EmailTextField;
    private javax.swing.JTextField ImieTextField;
    private javax.swing.JTextField NarodowoscTextField;
    private javax.swing.JTextField NazwiskoTextFiled;
    private javax.swing.JLabel NrLotuLabel;
    private javax.swing.JFormattedTextField TelefonTextField;
    private javax.swing.JLabel ZLabel;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration//GEN-END:variables
}
